//
// Created by cheng on 2021/02/01.
//

#include "Sort.h"


int BubbleSort(int *array, int length);

int main() {
    int arr[9] = {9,8,7,6,5,4,3,2,1};
    Sort::printArray(arr, 9);
    auto sw = BubbleSort(arr, 9);
    Sort::printArray(arr, 9);
    cout << sw << endl;
}

int BubbleSort(int *array, int length) {
    int sw = 0;
    bool flag = true;
    for (int i = 0; flag; ++i) {
        flag = false;
        for (int j = length-1; j >= i+1; --j) {
            if (array[j] < array[j-1]) {
                swap(array[j], array[j-1]);
                flag = true;
                sw++;
            }
        }
    }
    return sw;
}